<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>mytestAdmin</title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
		<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
		<link rel="stylesheet" href="./css/font.css">
		<link rel="stylesheet" href="./css/xadmin.css">
		<script type="text/javascript" src="js/jquery.min.js"></script>
		<script type="text/javascript" src="./lib/layui/layui.js" charset="utf-8"></script>
		<script type="text/javascript" src="./js/xadmin.js"></script>
		<script src="js/config.js" type="application/javascript"></script>
		<!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
		<!--[if lt IE 9]>
      <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
      <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
	</head>

	<body>
		<div class="x-body">
			<script type="text/html" id="toolbarDemo">
				<button class="layui-btn" onclick="fresh()"><i class="layui-icon">ဂ</i></button>
			</script>
			<table class="layui-hide" id="jobList" lay-filter="jobList"></table>

		</div>
		<script type="text/html" id="action">
			<a class="layui-btn layui-btn-xs" lay-event="add">加入用户</a>
		</script>
		<script>
			var id;
			layui.use('table', function() {
				var table = layui.table;

				table.render({
					elem: '#jobList', headers: {token: username,projectid: projectid},
					url: base_url + '/user/list',
					cellMinWidth: 80, //全局定义常规单元格的最小宽度，layui 2.2.1 新增
					toolbar: '#toolbarDemo',
					page: true,
					cols: [
						[{
							type: 'checkbox'
						}, {
							field: 'id',
							title: 'ID',
							width:100
						}, {
							field: 'username',
							title: '用户名'
						}, {
							fixed: 'right',
							title: '操作',
							toolbar: '#action',
							width: 120
						}]
					]
				});

				//监听行工具事件
				table.on('tool(jobList)', function(obj) {
					var data = obj.data;
					if(obj.event === 'add') {
						layer.confirm('确定添加该用户到项目吗？', function(index) {
							$.ajax({
								url: base_url + '/project/adduser/' + data.id,
								type: 'get',
								dataType: 'json',
								success: function(result) {
									console.log(result)
									if(result.code == '0') {
										var index = parent.layer.getFrameIndex(window.name);
										parent.layer.close(index);
									} else {
										layer.msg(result.msg);
									}
								}
							});
							layer.close(index);
						});
					}
				});
			});
		</script>
	</body>

</html>